home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / clipper / mrddem.zip / WINDOW.PRG < prev   
Text File  |  1994-06-29  |  20KB  |  495 lines

  1. #include "class(y).ch"
  2. #Include "Box.ch"
  3.  
  4. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  5.   │    Class│Window                                                          │
  6.   │  Purpose│A Window Class to creat windows on the screen. To give them     │
  7.   │         │headers, titles and anything else we can think of               │
  8.   │Date-Time│14/05/93      00:28:41                                          │
  9.   │Copyright│L&W Computer Services Ltd.                                      │
  10.   │   Author│Darren Lancaster                                                │
  11.   └─────────┴────────────────────────────────────────────────────────────────┘
  12. */
  13.  
  14. CREATE CLASS Window
  15.  
  16.    METHOD SayColor, WhoAmI
  17.  
  18. EXPORT:
  19.    VAR Cargo
  20.    VAR nTop, nLeft, nHeight, nWidth, nBottom, nRight,;
  21.        MaxRow, MaxCol, nRow, nCol                              TYPE NUMERIC
  22.    VAR cWindow, cOldScreen, cTitle, cTitleColor, cBackColor,;
  23.        cOffColor                                               TYPE CHARACTER
  24.    VAR lCanBeSeen, lFocus, lDisplayed                          TYPE LOGICAL
  25.  
  26.    CLASS VAR aStack                                            TYPE ARRAY
  27.    MESSAGE aStack TO CLASS
  28.  
  29.    METHOD Init, Display, Hide, Show, Close, paint, Title, HideAll, HideWindow,;
  30.           ShowWindow, SaveFront, RestFront, Say, SayC, DrawAll, Clear, DispWindow
  31.  
  32.    MESSAGE SetPos  METHOD Pos
  33.  
  34.    CLASS METHOD CloseAll
  35.  
  36. END CLASS
  37.  
  38. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  39.   │   Method│init(nTop, nLeft, nHeight, nWidth, cTitle)                      │
  40.   │  Purpose│This method is used to set up all the vars for the object       │
  41.   │         │                                                                │
  42.   │         │ nTop        : the top row, where the window will start         │
  43.   │         │ nLeft       : the left column, where the window will start     │
  44.   │         │ nHeight     : the number of rows that the window uses          │
  45.   │         │ nWidth      : the number of columns the window takes up        │
  46.   │         │ cTitleColor : the Title header color for the window            │
  47.   │         │ cBackColor  : the Window pane color                            │
  48.   │         │ cTitle      : the text to diaplay in the title bar             │
  49.   │         │ lCanBeSeen  : is the window being displayed                    │
  50.   │         │ aStack      : stack used to hold window number and position    │
  51.   │         │ lFocus      : is the window the output window                  │
  52.   │         │                                                                │
  53.   │         │                                                                │
  54.   │Date-Time│14/05/93      00:28:45                                          │
  55.   │Copyright│L&W Computer Services Ltd.                                      │
  56.   │   Author│Darren Lancaster                                                │
  57.   └─────────┴────────────────────────────────────────────────────────────────┘
  58. */
  59. METHOD init(nTop, nLeft, nHeight, nWidth, cTitle)
  60.  
  61.    IF nTop != NIL .AND. nLeft != NIL .AND. ValType(nHeight) != "N"
  62.       cTitle  := nHeight
  63.       nHeight := nTop
  64.       nWidth  := nLeft
  65.       nTop    := NIL
  66.       nLeft   := NIL
  67.    ENDIF
  68.  
  69.    IF nTop == NIL
  70.       nTop    := MaxRow() / 2 - (nHeight + 4) / 2
  71.    ENDIF
  72.  
  73.    IF nLeft == NIL
  74.       nLeft   := MaxCol() / 2 - (nWidth + 2) / 2
  75.    ENDIF
  76.  
  77.    IF nWidth < 1
  78.       nWidth := 1
  79.    ENDIF
  80.    IF nHeight < 1
  81.       nHeight := 1
  82.    ENDIF
  83.  
  84.    ::nTop := Int(nTop)
  85.    ::nLeft := Int(nLeft)
  86.    ::nHeight := Int(nHeight)
  87.    ::nWidth := Int(nWidth)
  88.    ::cOffColor := "W+"
  89.    ::cTitleColor := "GR+"
  90.    ::cBackColor := "B"
  91.    ::cTitle := If( !Empty(cTitle), cTitle,"")
  92.    ::lCanBeSeen := ::lDisplayed := .F.
  93.  
  94.    IF VALTYPE(::aStack) != "A"
  95.       :: class:aStack := {}
  96.    ENDIF
  97.  
  98.    aAdd(:: class:aStack, self)
  99.  
  100.    ::lFocus := .F.
  101.    ::nBottom := Int(nTop + nHeight + 3)
  102.    ::nRight := Int(nLeft + nWidth + 1)
  103.    ::nRow := ::nCol := 0
  104.    ::MaxRow := nHeight - 1
  105.    ::MaxCol := nWidth - 1
  106.  
  107. RETURN self
  108.  
  109. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  110.   │   Method│close                                                           │
  111.   │  Purpose│To remove the window from the stack and the display             │
  112.   │Date-Time│14/05/93      00:28:48                                          │
  113.   │Copyright│L&W Computer Services Ltd.                                      │
  114.   │   Author│Darren Lancaster                                                │
  115.   └─────────┴────────────────────────────────────────────────────────────────┘
  116. */
  117. METHOD Close
  118.  
  119.    @:Hide()
  120.    aDel(::aStack, @:WhoAmI())
  121.    aSize(::aStack, LEN(::aStack)-1)
  122.  
  123. RETURN self
  124.  
  125. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  126.   │   Method│WhoAmI() --> <nWindowNumber>                                    │
  127.   │  Purpose│Which window am I?                                              │
  128.   │Date-Time│05-24-93      09:55:42pm                                        │
  129.   │Copyright│L&W Computer Services Ltd.                                      │
  130.   │   Author│Ian Day                                                         │
  131.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  132. METHOD WhoAmI
  133. RETURN (aScan(::aStack, {|oWindow| oWindow == self }))
  134.  
  135. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  136.   │   Method│Display([<lFocus>]) --> self                                    │
  137.   │  Purpose│to draw a new window on the screen. Save the background first   │
  138.   │         │draw the box, draw the title                                    │
  139.   │Date-Time│14/05/93      00:28:55                                          │
  140.   │Copyright│L&W Computer Services Ltd.                                      │
  141.   │   Author│Darren Lancaster                                                │
  142.   └─────────┴────────────────────────────────────────────────────────────────┘
  143. */
  144. METHOD Display(lFocus)
  145.  
  146.    LOCAL oTemp, cSetColor
  147.  
  148.    IF ::lDisplayed
  149.       @:Show()
  150.    ELSE
  151.       IF ValType(lFocus) != "L"
  152.          lFocus := .T.
  153.       ENDIF
  154.  
  155.       IF !::lFocus
  156.          IF LEN(::aStack) > 1
  157.             IF lFocus
  158.                oTemp := ::aStack[LEN(::aStack) - 1]
  159.                oTemp:lFocus := .F.
  160.                cSetColor := SetColor(oTemp:cOffColor + "/" + oTemp:cBackColor)
  161.                SetColor(cSetColor)
  162.                oTemp:SaveFront()
  163.             ELSE
  164.                oTemp := Atail(::aStack)
  165.                aIns(::aStack, Len(::aStack) - 1)
  166.                ::aStack[Len(::aStack) - 1] := oTemp
  167.             ENDIF
  168.          ENDIF
  169.       ENDIF
  170.  
  171.       ::cOldScreen := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
  172.  
  173.       ::lCanBeSeen := .T.
  174.       ::lFocus := lFocus
  175.       @:Paint()
  176.       ::lDisplayed := .T.
  177.    ENDIF
  178.  
  179. RETURN self
  180.  
  181. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  182.   │   Method│Paint() --> self                                                │
  183.   │  Purpose│Paint the window                                                │
  184.   │Date-Time│05-19-93      11:51:13am                                        │
  185.   │Copyright│L&W Computer Services Ltd.                                      │
  186.   │   Author│Ian Day                                                         │
  187.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  188. METHOD Paint
  189.  
  190.    LOCAL cColor
  191.  
  192.    IF ::lCanBeSeen
  193.       DispBegin()
  194.       cColor := SetColor(If(::lFocus, ::cTitleColor, ::cOffColor) + "/" + ::cBackColor)
  195.  
  196.       ::DispWindow(.T.)
  197.       @:Title()
  198.  
  199.       ::cWindow := ""
  200.  
  201.       SetColor(cColor)
  202.       DispEnd()
  203.    ENDIF
  204.  
  205. RETURN (self)
  206.  
  207. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  208.   │   Method│Title() --> self                                                │
  209.   │  Purpose│Display the Title                                               │
  210.   │Date-Time│05-19-93      12:01:10pm                                        │
  211.   │Copyright│L&W Computer Services Ltd.                                      │
  212.   │   Author│Ian Day                                                         │
  213.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  214. METHOD Title()
  215.  
  216.    IF ::lCanBeSeen
  217.       @ ::nTop + 1, ::nLeft + 1 SAY PadC(::cTitle, ::nWidth) COLOR ::cTitleColor + "/" + ::cBackColor
  218.    ENDIF
  219.  
  220. RETURN (self)
  221.  
  222.  
  223. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  224.   │   Method│show                                                            │
  225.   │  Purpose│to show a window that has been hidden                           │
  226.   │Date-Time│14/05/93      00:28:53                                          │
  227.   │Copyright│L&W Computer Services Ltd.                                      │
  228.   │   Author│Darren Lancaster                                                │
  229.   └─────────┴────────────────────────────────────────────────────────────────┘
  230. */
  231. METHOD Show
  232.    LOCAL nX := 0, nWhoAmI := 0
  233.  
  234.    DispBegin()
  235.    @:HideAll()
  236.  
  237.    FOR nX := 1 TO LEN(:: class:aStack)
  238.       IF !(:: class:aStack[nX] == self)
  239.          :: class:aStack[nX]:lFocus := .F.
  240.       ELSE
  241.          nWhoAmI := nX
  242.       ENDIF
  243.    NEXT
  244.    ::lFocus := .T.
  245.    ::lCanBeSeen := .T.
  246.  
  247.    ADEL(:: class:aStack, nWhoAmI)
  248.    :: class:aStack[ LEN(:: class:aStack) ] := self
  249.  
  250.    @:DrawAll()
  251.    DispEnd()
  252.  
  253. RETURN self
  254.  
  255.  
  256. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  257.   │   Method│Hide                                                            │
  258.   │  Purpose│to restore the background and hide the window                   │
  259.   │Date-Time│14/05/93      00:28:59                                          │
  260.   │Copyright│L&W Computer Services Ltd.                                      │
  261.   │   Author│Darren Lancaster                                                │
  262.   └─────────┴────────────────────────────────────────────────────────────────┘
  263. */
  264. METHOD Hide
  265.    LOCAL nX, nWhoIsFocus := 0, oTemp
  266.  
  267.    IF ::lCanBeSeen
  268.       DispBegin()
  269.       @:HideAll()
  270.  
  271.       ::lCanBeSeen := .F.
  272.       ::lFocus := .F.
  273.  
  274.       FOR nX := 1 TO Len(::aStack)
  275.          IF ::aStack[nX]:lCanBeSeen
  276.             nWhoIsFocus := nX
  277.          ENDIF
  278.          ::aStack[nX]:lFocus := .F.
  279.       NEXT nX
  280.  
  281.       IF nWhoIsFocus > 0
  282.          ::aStack[nWhoIsFocus]:lFocus := .T.
  283.  
  284.          oTemp := ::aStack[nWhoIsFocus]            // Move newly focussed widow to top
  285.          aDel(::aStack, nWhoIsFocus)
  286.          ::aStack[Len(::aStack)] := oTemp
  287.       ENDIF
  288.  
  289.       @:DrawAll()
  290.       DispEnd()
  291.    ENDIF
  292.  
  293. RETURN self
  294.  
  295. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  296.   │   Method│HideAll() --> self                                              │
  297.   │  Purpose│Hide all the windows in the right order                         │
  298.   │Date-Time│05-19-93      12:21:18pm                                        │
  299.   │Copyright│L&W Computer Services Ltd.                                      │
  300.   │   Author│Ian Day                                                         │
  301.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  302. METHOD HideAll
  303.    LOCAL nX
  304.  
  305.    FOR nX := Len(::aStack) TO 1 STEP -1
  306.       IF ::aStack[nX]:lCanBeSeen
  307.          ::aStack[nX]:HideWindow()
  308.       ENDIF
  309.    NEXT nX
  310. RETURN(Self)
  311.  
  312. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  313.   │   Method│DrawAll() --> self                                              │
  314.   │  Purpose│Draw all of the windows                                         │
  315.   │Date-Time│05-19-93      11:24:14am                                        │
  316.   │Copyright│L&W Computer Services Ltd.                                      │
  317.   │   Author│Ian Day                                                         │
  318.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  319. METHOD DrawAll
  320.  
  321.    LOCAL nX
  322.  
  323.    FOR nX := 1 TO Len(::aStack)
  324.       IF ::aStack[nX]:lCanBeSeen
  325.          ::aStack[nX]:ShowWindow()
  326.       ENDIF
  327.    NEXT nX
  328.  
  329. RETURN (self)
  330.  
  331. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  332.   │   Method│HideWindow() --> self                                           │
  333.   │  Purpose│Save the image of the window and hide it                        │
  334.   │Date-Time│05-19-93      12:30:18pm                                        │
  335.   │Copyright│L&W Computer Services Ltd.                                      │
  336.   │   Author│Ian Day                                                         │
  337.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  338. METHOD HideWindow
  339.    IF ::lCanBeSeen
  340.       @:SaveFront()
  341.       RestScreen(::nTop, ::nLeft, ::nBottom, ::nRight, ::cOldScreen)
  342.    ENDIF
  343. RETURN (self)
  344.  
  345. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  346.   │   Method│ShowWindow                                                      │
  347.   │  Purpose│Restore the window back to the screen                           │
  348.   │Date-Time│05-19-93      12:31:57pm                                        │
  349.   │Copyright│L&W Computer Services Ltd.                                      │
  350.   │   Author│Ian Day                                                         │
  351.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  352. METHOD ShowWindow
  353.  
  354.    LOCAL cSetColor := SetColor(If(::lFocus, ::cTitleColor, ::cOffColor) + "/" + ::cBackColor)
  355.  
  356.    ::cOldScreen := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
  357.    @:RestFront()
  358.  
  359.    SetColor(cSetColor)
  360.  
  361. RETURN (self)
  362.  
  363. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  364.   │   Method│SaveFront() --> self                                            │
  365.   │  Purpose│Save the image of the window                                    │
  366.   │Date-Time│05-19-93      12:40:05pm                                        │
  367.   │Copyright│L&W Computer Services Ltd.                                      │
  368.   │   Author│Ian Day                                                         │
  369.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  370. METHOD SaveFront
  371.    IF ::lCanBeSeen
  372.       ::cWindow := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
  373.    ENDIF
  374. RETURN (self)
  375.  
  376. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  377.   │   Method│RestFront() --> self                                            │
  378.   │  Purpose│Restore the image of the window                                 │
  379.   │Date-Time│05-19-93      12:40:42pm                                        │
  380.   │Copyright│L&W Computer Services Ltd.                                      │
  381.   │   Author│Ian Day                                                         │
  382.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  383. METHOD RestFront
  384.    IF ::lCanBeSeen
  385.       RestScreen(::nTop, ::nLeft, ::nBottom, ::nRight, ::cWindow)
  386.    ENDIF
  387. RETURN (self)
  388.  
  389. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  390.   │   Method│SetPos([<nRow>], [<nCol>]) --> self                             │
  391.   │  Purpose│Position the windows' cursor                                    │
  392.   │Date-Time│05-19-93      12:50:03pm                                        │
  393.   │Copyright│L&W Computer Services Ltd.                                      │
  394.   │   Author│Ian Day                                                         │
  395.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  396. METHOD Pos(nRow, nCol)
  397.    ::nRow := If(ValType(nRow) == "N", Min(nRow, ::MaxRow), ::nRow)
  398.    ::nCol := If(ValType(nCol) == "N", Min(nCol, ::MaxCol), ::nCol)
  399. RETURN (self)
  400.  
  401. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  402.   │   Method│Say(<cString>, [<cForColour>]) --> self                         │
  403.   │  Purpose│Display a string in the window                                  │
  404.   │Date-Time│05-19-93      12:52:31pm                                        │
  405.   │Copyright│L&W Computer Services Ltd.                                      │
  406.   │   Author│Ian Day                                                         │
  407.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  408. METHOD Say(cString, cColour)
  409.  
  410.    @ ::nRow + ::nTop + 3, ::nCol + ::nLeft + 1 SAY Left(cString, ::nRight - (::nCol + ::nLeft) - 1) COLOR ::SayColor(cColour)
  411.    ::nCol += Len(cString)
  412.  
  413. RETURN (self)
  414.  
  415. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  416.   │   Method│SayColour(<cColour>) --> <cFullColour>                          │
  417.   │  Purpose│Get the complete colour string worked out                       │
  418.   │Date-Time│05-19-93      01:58:41pm                                        │
  419.   │Copyright│L&W Computer Services Ltd.                                      │
  420.   │   Author│Ian Day                                                         │
  421.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  422. METHOD SayColor(cColour)
  423.  
  424.    IF ValType(cColour) != "C"
  425.       cColour := "GR+/" + ::cBackColor
  426.    ELSEIF !("/" $ cColour)
  427.       cColour += "/" + ::cBackColor
  428.    ENDIF
  429.  
  430. RETURN(cColour)
  431.  
  432. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  433.   │   Method│SayC(<cString>, [<cColour>]) --> self                           │
  434.   │  Purpose│Display a centred string in the window                          │
  435.   │Date-Time│05-19-93      12:57:10pm                                        │
  436.   │Copyright│L&W Computer Services Ltd.                                      │
  437.   │   Author│Ian Day                                                         │
  438.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  439. METHOD SayC(cString, cColour)
  440.  
  441.    ::nCol := 0
  442.    @:Say(PadC(cString, ::MaxCol + 1), cColour)
  443.  
  444. RETURN (self)
  445.  
  446. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  447.   │   Method│Clear() --> self                                                │
  448.   │  Purpose│Clear area of window                                            │
  449.   │Date-Time│05-27-93      02:55:04pm                                        │
  450.   │Copyright│L&W Computer Services Ltd.                                      │
  451.   │   Author│Ian Day                                                         │
  452.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  453. METHOD Clear
  454.  
  455.    @ ::nTop + 3, ::nLeft + 1 CLEAR TO ::nBottom - 1, ::nRight - 1
  456.  
  457. RETURN (self)
  458.  
  459. /*┌─────────┬────────────────────────────────────────────────────────────────┐
  460.   │   Method│                                                                │
  461.   │  Purpose│                                                                │
  462.   │Date-Time│07-09-93      09:07:43pm                                        │
  463.   │Copyright│AWE&BS Ltd                                                      │
  464.   │   Author│Ian Day                                                         │
  465.   └─────────┴────────────────────────────────────────────────────────────────┘*/
  466. METHOD CloseAll
  467.  
  468.    @:HideAll()
  469.    ::aStack := {}
  470.  
  471. RETURN (self)
  472.  
  473.  
  474. /*┌─ Method ─────────────────────────────────────────────────────────────────┐
  475.   │         Name: DispWindow()                                               │
  476.   │  Description: Draw a window                                              │
  477.   │       Author: Darren Lancaster                                           │
  478.   │ Date created: 29-06-94              Date updated: ■29-06-94              │
  479.   │ Time created: 11:53:31am            Time updated: ■11:53:31am            │
  480.   │    Copyright: L&W Computer Services Ltd                                  │
  481.   └──────────────────────────────────────────────────────────────────────────┘
  482. */
  483. METHOD DispWindow(lClear)
  484.  
  485.    IF lClear
  486.       Scroll (::nTop, ::nLeft, ::nBottom, ::nRight, 0, 0)
  487.    ENDIF
  488.  
  489.    DispBox(::nTop, ::nLeft, ::nBottom, ::nRight, B_DOUBLE)
  490.    @ ::nTop+2, ::nLeft SAY "╠"
  491.    @ ::nTop+2, ::nRight SAY "╣"
  492.    DispBox(::nTop+2, ::nLeft+1, ::nTop+2, ::nRight-1, B_DOUBLE)
  493. RETURN(self)
  494.  
  495.